package com.rtf.framework.web.mvc.rest.dict;

import com.rtf.framework.dao.jpa.AppJpaDataRepository;
import com.rtf.framework.dao.jpa.annotation.MybatisQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

public interface SysDictDao extends AppJpaDataRepository<SysDict, Long> {
    @MybatisQuery
    @Select("SELECT * FROM sys_dict WHERE parent_id IN (" +
            "   SELECT id FROM sys_dict WHERE code = #{code}" +
            ")")
    List<SysDict> querySubDictByCode(@Param("code") String code);

    @MybatisQuery
    @Select("<script>" +
            "SELECT * FROM sys_dict " +
            "WHERE " +
            "<foreach item=\"parentId\" collection=\"parentIds\" open=\"\" separator=\" OR \" close=\"\">" +
            "   level_path LIKE CONCAT(#{parentId},';%')" +
            "</foreach>" +
            "</script>")
    List<SysDict> queryClassifyByLevelPath(@Param("parentIds") Collection<Long> parentIds);
}
